package com.sskj.mine.verify;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.bean.ImgHighBean;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.presenter.BasePresenter;

import java.io.File;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;


/**
 * @author Hey
 * Create at  2019/05/01
 */
class VerifySecondPresenter extends BasePresenter<VerifySecondActivity> {

    public void submitVerify(File file, int position) {
        OkGo.<HttpData<ImgHighBean>>post(HttpConfig.BASE_URL + HttpConfig.HIGH_VERIFY_IMG)
                .isMultipart(false)
                .params("file", file)
                .execute(new JsonCallBack<HttpData<ImgHighBean>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<ImgHighBean>> response) {
                        HttpData body = response.body();
                        if (body.status == HttpConfig.OK) {
                            ToastUtil.showShort(body.msg);
                            ImgHighBean hignBean = (ImgHighBean) body.getData();
                            mView.putList(hignBean.getUrl(), position);
                        }
                    }

                    @Override
                    public void onError(Response<HttpData<ImgHighBean>> response) {
                        super.onError(response);
                        HttpData body = response.body();
                        mView.uploadFail(position);
                        ToastUtil.showShort(body.msg);
                    }
                });
    }


    // 实名二级认证
    public void verifySecond(String cardimg1, String cardimg2, String cardimg3,String cardimg4) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.HIGH_VERIFY)
                .params("cardimg1", cardimg1)  // 正面
                .params("cardimg2", cardimg2)//身份证背面
                .params("cardimg3", cardimg3)
                .params("cardimg4", cardimg4)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        if (body.getStatus() == HttpConfig.OK) {
                            ToastUtil.showShort(body.getMsg());
                            mView.verifySecondSuccess();
                        }
                    }
                });
    }


}
